package cz.fit.vutbr.pis2012.augeaswh.control.ekonom.orders;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.richfaces.component.SortOrder;

@ManagedBean
@ViewScoped
public class OrdersSortingBean implements Serializable {

	private static final long serialVersionUID = 6603374489356711484L;
	private SortOrder nameOrder = SortOrder.ascending;
    private SortOrder incomeDateOrder = SortOrder.unsorted;
    private SortOrder subscriberOrder = SortOrder.unsorted;
           
    public void sortByName() {
    	incomeDateOrder = SortOrder.unsorted;
        subscriberOrder = SortOrder.unsorted;
           
        if (nameOrder.equals(SortOrder.ascending)) {
            setNameOrder(SortOrder.descending);
        } else {
        	setNameOrder(SortOrder.ascending);
        }
    }
    
    public void sortByIncomeDate() {
        nameOrder = SortOrder.unsorted;
        subscriberOrder = SortOrder.unsorted;
           
        if (incomeDateOrder.equals(SortOrder.ascending)) {
            setIncomeDateOrder(SortOrder.descending);
        } else {
        	setIncomeDateOrder(SortOrder.ascending);
        }
    }
    
    public void sortBySubscriber() {
        nameOrder = SortOrder.unsorted;
        incomeDateOrder = SortOrder.unsorted;
        
        if (subscriberOrder.equals(SortOrder.ascending)) {
            setSubscriberOrder(SortOrder.descending);
        } else {
        	setSubscriberOrder(SortOrder.ascending);
        }
    }
    
   	public SortOrder getNameOrder() {
		return nameOrder;
	}

	public void setNameOrder(SortOrder nameOrder) {
		this.nameOrder = nameOrder;
	}

	public SortOrder getIncomeDateOrder() {
		return incomeDateOrder;
	}

	public void setIncomeDateOrder(SortOrder incomeDateOrder) {
		this.incomeDateOrder = incomeDateOrder;
	}

	public SortOrder getSubscriberOrder() {
		return subscriberOrder;
	}

	public void setSubscriberOrder(SortOrder subscriberOrder) {
		this.subscriberOrder = subscriberOrder;
	}
}
